def process_data(data):
    for key in data:
        for task_c in range(len(data[key])):
            size = len(data[key][task_c])
            for j in range(size - 1):
                state, time = data[key][task_c][j]
                next_state, next_time = data[key][task_c][j + 1]
                new_state = ''
                if state in ["Active", "CycOn"]:
                    new_state = 'O'     # 运行
                elif state == "CycDown":
                    new_state = 'I'    # 循环中空闲
                elif state in ['Failed', 'Maintenance', 'NAM','Maintenance_SOF']:
                    new_state = 'F'     
                elif state in ['Dormant', 'Warm']:
                    new_state = 'S'
                new_time = next_time - time
                data[key][task_c][j] = (new_state, new_time)
            if data[key][task_c]:
                del data[key][task_c][size - 1]
    return data
'''
# 测试函数
data = {
    'X1': [[('Active', 0.0), ('Failed', 100.59700395954962), ('Failed', 1000.0)], [('Failed', 0.0), ('Failed', 1000.0)]],
    'X2': [[('Active', 0.0), ('Failed', 420.5753681566853), ('Failed', 1000.0)], [('Failed', 0.0), ('Failed', 1000.0)]],
    '总体': [[('Active', 0.0), ('Failed', 420.5753681566853), ('Failed', 1000.0)], [('Failed', 0.0), ('Failed', 1000.0)]],
    'TASK20240815': [[('Active', 0.0), ('Failed', 420.5753681566853), ('Failed', 1000.0)], [('Failed', 0.0), ('Failed', 1000.0)]]
}

print("原始数据:")
print(data)

processed_data = process_data(data)

print("处理后的数据:")
print(processed_data)
'''